package com.socialvampic.login;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.social.vampic.R;
import com.socialvampic.mvc.view.AbstractView;

public class LoginView extends AbstractView {
	private TextView mSignInWithFbTextView;
	private Button mSignInWithFbButton;
	private TextView mSignInWithVampicTextView;
	private Button mSignInWithVampicButton;
	private TextView mCreateVampicTextView;
	private Button mCreateVampicButton;

	private OnLoginScreenListener mLoginListener;

	public LoginView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	public LoginView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void createView(LayoutInflater inflater, ViewGroup container) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.login_screen, this);

		mSignInWithFbButton = (Button) view
				.findViewById(R.id.sign_in_with_facebook_button);
		mSignInWithFbTextView = (TextView) view
				.findViewById(R.id.sign_in_with_facebook_textview);
		mSignInWithVampicButton = (Button) view
				.findViewById(R.id.sign_in_with_exists_account_button);
		mSignInWithVampicTextView = (TextView) view
				.findViewById(R.id.sign_in_with_exists_account_textview);
		mCreateVampicButton = (Button) view
				.findViewById(R.id.create_new_account_button);
		mCreateVampicTextView = (TextView) view
				.findViewById(R.id.create_new_account_textview);

		mSignInWithFbButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (mLoginListener != null) {
					mLoginListener.onSignInWithFacebookClicked();
				}
			}
		});

		mSignInWithVampicButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (mLoginListener != null) {
					mLoginListener.onSignInWithVampicAccountClicked();
				}
			}
		});

		mCreateVampicButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (mLoginListener != null) {
					mLoginListener.onCreateVampicAccountClicked();
				}
			}
		});
	}

	@Override
	public void destroyView() {
		// TODO Auto-generated method stub
		super.destroyView();
		removeAllViews();
		setOnLoginListener(null);
		mCreateVampicButton.setOnClickListener(null);
		mSignInWithFbButton.setOnClickListener(null);
		mSignInWithVampicButton.setOnClickListener(null);
	}

	@Override
	public void reloadView() {
		// TODO Auto-generated method stub
		mSignInWithFbButton
				.setText(R.string.login_sign_in_with_facebook_button);
		mSignInWithFbTextView
				.setText(R.string.login_sign_in_with_facebook_textview);
		mSignInWithVampicButton
				.setText(R.string.login_sign_in_with_exists_account_button);
		mSignInWithVampicTextView
				.setText(R.string.login_sign_in_with_exists_account_textview);
		mCreateVampicButton.setText(R.string.login_create_new_account_button);
		mCreateVampicTextView
				.setText(R.string.login_sign_in_with_exists_account_textview);
	}

	public void setOnLoginListener(OnLoginScreenListener listener) {
		mLoginListener = listener;
	}

	/**
	 * Handle event on login screen
	 * 
	 * @author trungduy
	 * 
	 */
	public static interface OnLoginScreenListener {
		// sign in with facebook button
		public void onSignInWithFacebookClicked();

		// sign in with vampic account button
		public void onSignInWithVampicAccountClicked();

		// create new vampic account
		public void onCreateVampicAccountClicked();
	}
}
